package com.htc.callcare.viewcontroller;

import com.htc.callcare.R;
import com.htc.callcare.activities.RecordActivity;
import com.htc.callcare.database.Database;
import com.htc.callcare.model.NoteModel;
import com.htc.callcare.model.recordModel;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;

public class Record_Note_View extends LinearLayout{

	Button done;
	EditText notePad;
	recordModel model;
	Context context;
	Database database;
	RecordActivity recordActivity;
	public Record_Note_View(final Context context) {
		super(context);
		this.context = context;
		LayoutInflater.from(context).inflate(R.layout.record_note, this, true);
		done = (Button) findViewById(R.id.record_note_done);
		notePad = (EditText) findViewById(R.id.edtNote);
		database = new Database(context);
		done.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
				imm.hideSoftInputFromWindow(notePad.getWindowToken(), 0);
				if(database.findNote(model.getFileUri()).equals("")){
					NoteModel note = new NoteModel(model.getFileUri(), notePad.getText().toString().trim());
					database.addNote(note);
				}
				else{
					database.updateNote(model.getFileUri(), notePad.getText().toString().trim());
				}
				
				Record_Note_View.this.setVisibility(GONE);
				recordActivity.updateAdapter();
			}
		});
		
	}
	public void setProcessModel(recordModel processModel, RecordActivity recordActivity) {
		// TODO Auto-generated method stub
		model = processModel;
		this.recordActivity = recordActivity;
		notePad.setText(model.getNote());
	}
	/*public View getNotePad() {
		// TODO Auto-generated method stub
		return notePad;
	}*/
	
	

}
